using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tecmosuperbowlmanager
{
   
    public partial class tsbUIportal : Form
    {
        public static romReader rom;
        private static FormGameOptions game_options;        
        private static string pathFileName;

        public tsbUIportal()
        {            
            InitializeComponent();                  
            

        }

        private void importDataFromRomToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            pathFileName = openFileDialog1.FileName;            
            toolStripStatusLabel1.Text = pathFileName;
            rom = null;
            rom = new romReader(pathFileName);
            saveFileDialog1.FileName = pathFileName;
            saveRomToolStripMenuItem.Enabled = true;
            saveRomAsToolStripMenuItem.Enabled = true;
            editorOptionsToolStripMenuItem.Visible = true;
            initializeGameOptionsToolStripMenuItem();
            game_options.numericUpDownQuarterLength.Value = rom.QuarterLength;
            game_options.textBoxQuarterCurrent.Text = rom.QuarterLength.ToString();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = System.Windows.Forms.MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                Environment.Exit(0);
            }
            
        }

        private void initializeGameOptionsToolStripMenuItem()
        {
            if (game_options != null)
            {
                game_options.Close();
            }
            game_options = new FormGameOptions();
            game_options.MdiParent = this;
            game_options.Show();
            game_options.numericUpDownQuarterLength.ValueChanged += new EventHandler(numericUpDownQuarterLength_ValueChanged);
        }

        private void gameOptionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (game_options == null)
            {
                initializeGameOptionsToolStripMenuItem();
            }
            if (game_options != null)
            {
                game_options.Show();
            }                                   
        }

        private void tsbUIportal_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = false;
        }

        private void saveRomAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
            string pathName = saveFileDialog1.FileName;
            writeRom writer = new writeRom(pathName);
            writer.writeFile(rom.BytesOfFile);
           // rom = null;
            //rom = new romReader(pathFileName);
        }

        private void numericUpDownQuarterLength_ValueChanged(object sender, EventArgs e)
        {
            rom.QuarterLength = Convert.ToInt32(game_options.numericUpDownQuarterLength.Value);
        }
    }
}